package com.example.demo.mapper;

import com.example.demo.croe.ScheduledTaskBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 定时任务表 mapper
 * demo 项目未使用 xml方式，使用注解方式查询数据以便演示
 */
@Mapper
public interface ScheduledTaskMapper  {

    /**
     * 根据key 获取 任务信息
     */
    @Select("select task_key as taskKey,task_desc as taskDesc,task_cron as taskCron,init_start_flag as initStartFlag  from scheduled_task where task_key = '${taskKey}' ")
    ScheduledTaskBean getByKey(@Param("taskKey") String taskKey);

    /**
     * 获取程序初始化需要自启的任务信息
     */
    @Select("select task_key as taskKey,task_desc as taskDesc,task_cron as taskCron,init_start_flag as initStartFlag from scheduled_task where init_start_flag=1 ")
    List<ScheduledTaskBean> getAllNeedStartTask();

    /**
     * 获取所有任务
     */
    @Select("select task_key as taskKey,task_desc as taskDesc,task_cron as taskCron,init_start_flag as initStartFlag  from scheduled_task ")
    List<ScheduledTaskBean> getAllTask();
    @Update("UPDATE scheduled_task SET task_cron = '${croe}' where  task_key = '${taskKey}' ")
    void setCroe(String taskKey, String croe);

    @Insert({"INSERT INTO  scheduled_task(id, task_key, task_desc, task_cron, init_start_flag) VALUES ( #{uuid},#{taskKey},#{taskDesc},#{taskCron},#{initStartFlag})"})
    void insertTask(String uuid, String taskKey, String taskDesc, String taskCron, Integer initStartFlag);
}
